package com.ruoyi.system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.system.domain.BScoreRule;
import com.ruoyi.system.domain.BTaskScore;
import com.ruoyi.system.domain.vo.BProjectTaskVo;
import com.ruoyi.system.domain.vo.BScoreRuleVo;
import com.ruoyi.system.service.BTaskScoreService;
import com.ruoyi.system.mapper.BTaskScoreMapper;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
* @author yangxingze
* @description 针对表【b_task_score(训练评分记录表)】的数据库操作Service实现
* @createDate 2024-12-28 00:45:04
*/
@Service
public class BTaskScoreServiceImpl extends ServiceImpl<BTaskScoreMapper, BTaskScore>
    implements BTaskScoreService{

    /**
     * 保存评分信息
     * @param taskVo
     * @return
     */
    @Override
    public boolean saveScore(BProjectTaskVo taskVo) {
        try{
            //删除旧数据
            baseMapper.deleteByTaskId(taskVo.getId());
            //保存新数据
            List<BScoreRuleVo> scoreRuleVos = taskVo.getScoreRuleList();
            for(BScoreRuleVo scoreRuleVo : scoreRuleVos){
                BTaskScore taskScore = new BTaskScore();
                taskScore.setProjectTaskId(taskVo.getId());
                taskScore.setProjectId(taskVo.getProjectId());
                taskScore.setScoreId(scoreRuleVo.getId());
                taskScore.setName(scoreRuleVo.getName());
                taskScore.setScore(scoreRuleVo.getScore());
                taskScore.setCreateTime(new Date());
                this.save(taskScore);
            }
            return true;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }

    }
}




